package com.fastloan.mgt.verify.controller;

import com.fastloan.mgt.customer.model.KXBankCardResult;
import com.fastloan.mgt.verify.model.personbank.PersonBankParam;
import com.fastloan.mgt.verify.model.personbank.VerifyCode;
import com.fastloan.mgt.verify.model.tobacco.TobaccoICertificate;
import com.fastloan.mgt.verify.service.PersonBankVerifyService;
import com.fastloan.mgt.verify.service.TobaccoICertificateVerifyService;
import com.fastloan.mgt.verify.service.VerifyService;
import com.kawins.result.ResultTo;
import com.kawins.spring.valid.core.BeanValid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 三方验证
 *
 * @author yanwe
 * createTime 2017-12-2017/12/15 18:45
 */
@RestController
@RequestMapping("/api/verify")
public class VerifyController {

    @Autowired
    private PersonBankVerifyService personBankVerifyService;

    @Autowired
    private TobaccoICertificateVerifyService tobaccoICertificateVerifyService;

    @Autowired
    private VerifyService verifyService;

    /**
     * 获得人行征信验证码
     *
     * @return 验证码
     */
    @GetMapping("/personBank/verifyCode")
    public ResultTo getPersonBankVerifyCode(){
        VerifyCode verifyCode = personBankVerifyService.getVerifyCode();
        return new ResultTo().setData(verifyCode);
    }

    /**
     * 人行征信验证
     *
     * @param applicationId 进件id
     * @param personBankParam 验证信息
     * @return 结果
     */
    @BeanValid
    @PostMapping("/personBank/{applicationId}")
    public ResultTo personBankVerify(@PathVariable("applicationId") String applicationId
            , @Valid PersonBankParam personBankParam){
        return personBankVerifyService.personBankVerify(applicationId,personBankParam);
    }

    /**
     * 烟商验证
     *
     * @param applicationId 进件id
     * @param tobaccoICertificate 验证信息
     * @return 结果
     */
    @BeanValid
    @PostMapping("/tobaccoICertificate/{applicationId}")
    public ResultTo tobaccoVerify(@PathVariable("applicationId") String applicationId
            , @Valid TobaccoICertificate tobaccoICertificate){
        return tobaccoICertificateVerifyService.tobaccoICertificateVerify(applicationId,tobaccoICertificate);
    }

    /**
     * 银行卡查询
     *
     * @param cardNum 银行卡
     * @return 查询结果
     */
    @GetMapping("/select/bankCard/{cardNum}")
    public ResultTo bankCard(@PathVariable("cardNum") String cardNum){
        KXBankCardResult kxBankCardResult = verifyService.selectBankCardType(cardNum);
        return new ResultTo().setData(kxBankCardResult);
    }
}
